const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = function (env, argv) {
    let config =null;

    if (env.dev) {
        //开发环境
        config =require('./config/webpack.dev.js');
    } else if (env.pord) {
        //生产环境
        config =require('./config/webpack.pord.js');
    } else {
        //测试环境
        config =require('./config/webpack.test.js');
    }

    return {
        entry: './src/index.js',
        module: {
            rules: [
                //js或者jsx
                {
                    test: /\.jsx?/i,
                    exclude: /node_modules/,
                    use: {
                        loader: 'babel-loader',
                        options: {
                            presets: ['@babel/preset-react']
                        }
                    }
                },
                //css
                { test: /\.css/i, exclude: /node_modules/, use: ['style-loader', 'css-loader'] },
                //图片
                {
                    test: /\.png/i, use: {
                        loader: 'file-loader',
                        options: {
                            outputPath: './imgs',
                        }
                    }
                }

            ]
        },
        plugins: [
            new HtmlWebpackPlugin({
                template: path.resolve(__dirname, 'index.html')
            })
        ],
        ...config

    };

};